<template>
  <div class="duanhuo">
    <div class="xiangqing-header">
      <img @click="Back()" class="back" src="../../assets/img/shouye/header-xinpin/back.png" />
      <p>限时断货</p>
      <div class="share">
        <img src="../../assets/img/shouye/shouye-shangpinxiangqing/购物车前.png"/>
        <img @click="isFX = true"  src="../../assets/img/shouye/header-xinpin/share.png" />
        <router-link :to="{name: 'shouye/tuijian'}">
          <img src="../../assets/img/shouye/shouye-shangpinxiangqing/首页.png"/>
        </router-link>
      </div>
    </div>
    <h3>宝贝即将售罄，再不抢就没了哦~</h3>
    <ul class="goods">
      <li v-for="good in Arr">
        <ul class="good-list">
          <li>
            <div>
              <router-link :to="{name: 'shangpinxiangqing', params: {good}}">
                <img :src="good.src" alt="">
              </router-link>
            </div>
          </li>
          <li>
            <h4>{{good.name}}</h4>
            <h5>{{good.desc}}</h5>
            <h6>￥{{good.price}}</h6>
          </li>
          <li>
            <p>马上抢 > </p>
            <span>还剩<span>01:59:59</span></span>
          </li>
        </ul>
      </li>
    </ul>
    <div class="fenxiang-mengban" v-if="isFX">
      <div class="fenxiang">
        <ul>
          <li>
            <ul class="fenxiang-list">
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/pengyouquan.png"/>
                </div>
                <p>微信朋友圈</p>
              </li>
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/weixin.png" /></div>
                <p>微信好友</p>
              </li>
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/QQ.png"/></div>
                <p>QQ好友</p>
              </li>
            </ul>
          </li>
          <li>
            <ul class="fenxiang-list">
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/QQkongjian.png"/></div>
                <p>QQ空间</p>
              </li>
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/weibo.png" /></div>
                <p>微博</p>
              </li>
              <li>
                <div>
                  <img src="../../assets/img/shouye/fenxiang/fuzhilianjie.png"/></div>
                <p>复制链接</p>
              </li>
            </ul>
          </li>
        </ul>
        <div @click="quxiao()">
          取消
        </div>
      </div>
    </div>
    <div class="up" @click="toTop()" v-if="isUP">
      <img src="../../assets/img/shouye/tuijian-xuanliyanzhuang/toTop.png"/>
    </div>
  </div>
</template>
<script>
  import Vue from 'vue'
  export default {
    data () {
      return {
        isFX: false,
        isUP: false,
        Arr: [],
        arr: []
      }
    },
    methods: {
      Back () {
        this.$router.go(-1)
      },
      quxiao () {
        this.isFX = false;
      },
      toTop () {
        if(document.documentElement){
          document.documentElement.scrollTop = 0;
        }else{
          document.body.scrollTop = 0;
        }
      },
      menu() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
        if(this.scroll > 0){
          //显示 a 标签
          this.isUP = true;
        }else{
          //隐藏 a 标签
          this.isUP = false;
        }
      },
      top () {
        window.scrollTo(0,0)
      },
      tuijianGet() {
        //  发起get请求
        //  设置代理服务器转发的域
        Vue.axios.get('/api/get', {
//              get传递的query参数
//            params: {
//              name: 'along',
//              age: 32
//            }
        }).then( (response) => {
          //  成功之后的回调
//          console.log(response.data);
          this.Arr = this.arr = response.data;
//          console.log(this.arr);
//          for (let i = 0 ; i < this.arr.length; i ++) {
//            if (this.arr[i].sc === '奶粉') {
//              this.Arr.push(this.arr[i]);
//            } else if (this.arr[i].sc === '纸尿裤') {
//              this.zArr.push(this.arr[i]);
//            }
//          }
        }).catch( (error) => {
          //  请求出错的处理
          console.log(error)
        });
      }
    },
    mounted() {
      window.addEventListener('scroll', this.menu);
      this.tuijianGet();
    },
    created () {
      this.top();
    }
  }
</script>
<style scoped>
  .duanhuo {
    background: #f2f2f2;
    position: relative;
    padding-top: 2rem;
    width: 100%;
  }
  .xiangqing-header {
    width: 100%;
    height: 2rem;
    line-height: 2rem;
    background: #e53e42;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
  }
  .back {
    vertical-align: middle;
    width: 0.6rem;
    margin-left: 0.5rem;
  }
  .xiangqing-header>p{
    width: 8rem;
    padding-left: 2.5rem;
    height: 100%;
    text-align: center;
    display: inline-block;
    font-family: MicrosoftYaHei;
    font-size: 0.7rem;
    font-weight: normal;
    font-stretch: normal;
    color: #ffffff;

  }
  .share {
    display: inline-block;
  }
  .share img {
    vertical-align: middle;
    width: 0.8rem;
  }
  .duanhuo h3 {
    padding: 0.5rem;
    font-family: MicrosoftYaHei;
    font-size: 0.8rem;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 0.03rem;
    color: #4d4d4d;
  }
  .good-list{
    display: flex;
    background: #fff;
    padding: 0.5rem 0;
    border-bottom: 1px solid #ccc;
  }
  .good-list li:nth-child(1) {
    flex: 1;
  }
  .good-list li:nth-child(2) {
    flex: 5;
    padding-left: 0.5rem;
  }
  .good-list li:nth-child(3) {
    flex: 1;
    margin-top: 1rem;
    transform: scale(0.8);
  }
  .good-list div{
    padding-left: 0.5rem;
    width: 3rem;
    height: 3rem;
    text-align: center;
    line-height: 3rem;
  }
  .good-list img{
    max-width: 100%;
    max-height: 100%;
    vertical-align: middle;
  }
  .good-list h4 {
    font-size: 0.8rem;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 0.03rem;
    color: #333333;
  }
  .good-list h5 {
    font-size: 0.6rem;
    font-weight: normal;
    font-stretch: normal;
    color: #333333;
  }
  .good-list h6 {
    font-size: 0.6rem;
    font-weight: normal;
    font-stretch: normal;
    color: #333333;
  }
  .good-list p {
    text-align: center;
    font-size: 0.6rem;
    font-weight: normal;
    font-stretch: normal;
    color: #ffffff;
    width: 4rem;
    background-color: #e53e42;
    border-radius: 0.5rem;
  }
  .good-list span {
    font-size: 0.5rem;
    font-weight: normal;
    font-stretch: normal;
    color: #333;
    padding-left: 0.4rem;
  }
  .good-list span>span {
    font-size: 0.5rem;
    font-weight: normal;
    font-stretch: normal;
    color: #e53e42;
  }
  .fenxiang-mengban {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    background: rgba(0,0,0,0.5);
  }
  .fenxiang {
    padding-top: 1rem;
    background: #fff;
    width: 100%;
    height: 10rem;
    position: absolute;
    bottom: 0;
    left: 0;
  }
  .fenxiang-list {
    display: flex;
  }
  .fenxiang-list li {
    flex: 1;
    text-align: center;
  }
  .fenxiang-list div {
    width: 1.5rem;
    height: 1.5rem;
    margin: 0.5rem auto;
  }
  .fenxiang-list div img {
    width: 100%;
  }
  .fenxiang-list p {
    font-size: 0.6rem;
    font-weight: normal;
    font-stretch: normal;
    color: #4d4d4d;
  }
  .fenxiang>div {
    font-size: 0.6rem;
    font-weight: normal;
    font-stretch: normal;
    background: #e53e42;
    color: #fff;
    width: 3rem;
    text-align: center;
    padding: 0.2rem;
    border-radius: 0.2rem;
    margin: 0.5rem auto;
  }
  .up {
    width: 1.5rem;
    position: fixed;
    bottom: 0;
    right: 0.3rem;
  }
  .up img {
    width: 100%;
  }
</style>
